package com.xiaoniu.tcp;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import io.vertx.ext.web.Router;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalUnit;

public class MainVerticle extends AbstractVerticle {

  public static void main(String[] args) {
    Vertx.vertx().deployVerticle(new MainVerticle());
//    LocalDate now = LocalDate.now();
//    LocalDate plus = now.plus(30, ChronoUnit.DAYS);
//    System.out.println(now.toString());
//    System.out.println(plus.toString());
  }

  private static final Logger log = LoggerFactory.getLogger(MainVerticle.class);

  @Override
  public void start() throws Exception {

    Router router = Router.router(vertx);
    router.get("/api/:name/getMusic").handler(ctx -> {
      System.out.println("getMusic");
      String name = ctx.pathParam("name");
      String fileName = "C:\\CloudMusic\\"+name+".mp3";
      System.out.println(fileName);
      ctx.response().sendFile(fileName);
    });

    vertx.createHttpServer().requestHandler(router::accept).listen(8080, res -> {
      if (res.succeeded()) {
        System.out.println("HTTP server started on port 8080");
      } else {
        res.cause().printStackTrace();
      }
    });
  }
}
